Ext.namespace("AuditPlan");
/*
AuditPlan.audits = {
	marketweekly: null,
	groupweekly: null,
	adminweekly: null,
	busiweekly: null,
	adminmonthly: null
};
AuditPlan.initAudit = {
	'1': function(p) {
		if (AuditPlan.audits.marketweekly == null) {
			AuditPlan.audits.marketweekly = new AuditPlan.MarketWeeklyAudit(p);
		}
		return AuditPlan.audits.marketweekly;
	},
	'2': function(p) {
		if (AuditPlan.audits.groupweekly == null) {
			AuditPlan.audits.groupweekly = new AuditPlan.GroupWeeklyAudit(p);
		}
		return AuditPlan.audits.groupweekly;
	},
	'3': function(p) {
		if (AuditPlan.audits.adminweekly == null) {
			AuditPlan.audits.adminweekly = new AuditPlan.AdminWeeklyAudit(p);
		}
		return AuditPlan.audits.adminweekly;
	},
	'4': function(p) {
		if (AuditPlan.audits.busiweekly == null) {
			AuditPlan.audits.busiweekly = new AuditPlan.BusiWeeklyAudit(p);
		}
		return AuditPlan.audits.busiweekly;
	},
	'5': function(p) {
		if (AuditPlan.audits.adminmonthly == null) {
			AuditPlan.audits.adminmonthly = new AuditPlan.AdminMonthlyAudit(p);
		}
		return AuditPlan.audits.adminmonthly;
	},
};
* */
AuditPlan.ToAudit = function() {
	this.winAudit = null;
	this.winView = null;
	this.store = new Ext.data.JsonStore({
	    url: Utils.formatURL('../auditplan/toAuditPlan.form?timesnap=' + Date.parse(new Date())),
	    root: 'result',
	    fields: ['planId', 'planName','planType','createId','createName','auditorName','startDate','endDate']
	});
	this.renderType = function(value){
		return OMS.PLANTYPE[value];
	};
	this.renderExport=function(value){
		var url='../auditplan/exportPlan.form?planId='+value+'&timesnap=' + Date.parse(new Date());
		return '<a href="'+url+'" >导出</a>';
	}
	this.column = [
		  {header: '计划编号', sortable: true, align: 'left',hidden:true, dataIndex: 'planId'},
		  {header: '审核人名称', sortable: true, align: 'left',hidden:true, dataIndex: 'auditorName'},
		  {header: '计划名称', sortable: true, align: 'left', dataIndex: 'planName'},
	      {header: '计划类型', sortable: true, align: 'center',width: 20, dataIndex: 'planType',renderer:this.renderType},
	      {header: '开始时间', sortable: true, align: 'center', width: 20, dataIndex: 'startDate'},	      
	      {header: '结束时间', sortable: true, align: 'center', width: 20, dataIndex: 'endDate'},
	      {header: '制定人', sortable: true, align: 'left',width: 40, dataIndex: 'createName'},
	      {header: '创建人ID', sortable: true, align: 'left',hidden:true, dataIndex: 'createId'},
	      {header: '导出',  align: 'center',width: 40, dataIndex: 'planId',renderer:this.renderExport}
	];
	
	this.btnAuditPlan = new Ext.Button({
		text: '审核计划',
		iconCls: 'icon-submitplan',
		scope: this,
		handler: this.onAuditPlan
	});
	this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '查找',
        tooltip: {text: '查找计划'},
        handler: this.queryPlan,
        scope: this
    });
	this.bbar=new Ext.PagingToolbar({
		 pageSize: 15,
         store: this.store,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
	});
	AuditPlan.ToAudit.superclass.constructor.call(this, {
		title: '待审核计划',
        region: 'center',
        tbar: [this.btnAuditPlan,'->',this.btnSearch],
        cm: new Ext.grid.ColumnModel(this.column),
        viewConfig: { forceFit: true },
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        bbar:this.bbar,
        store:this.store,
        listeners:{
        	rowdblclick : this.onView,
			//render:this.queryPlan
			activate: this.queryPlan
		}
    });
};
Ext.extend(AuditPlan.ToAudit, Ext.grid.GridPanel, {
	onAuditPlan: function(btn, event) {
		var record = this.getSelectionModel().getSelected();
		if(!record){
			Utils.warn2('请选择一条计划！',180);
			return ;
		}
		/*
		var planType=record.data.planType;
		if (!AuditPlan.initAudit[planType]) {
			Utils.info('无效计划类型，请联系管理员!');
			return;
		}		
		this.winAudit = AuditPlan.initAudit[planType](this);*/
		if (this.winAudit == null) {
			this.winAudit = new AuditPlan.WeeklyAudit(this);
		}
		this.winAudit.show(); 
		this.winAudit.initWin(record.data);		
	},
	onView:function(grid, rowIndex,e){	
		if (this.winView == null) {
			this.winView = new MyPlan.WeeklyView(this);
		}
		this.winView.show();
		this.winView.initWin(grid.store.getAt(rowIndex).data);		
	},
	queryPlan:function(btn,event){
		this.store.load({
			params:{
				start : 0,
				limit : 15
				}
		});
	}
});
